package com.wilmer.children.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wilmer.common.annotation.Log;
import com.wilmer.common.core.controller.BaseController;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.enums.BusinessType;
import com.wilmer.children.domain.YwChildren;
import com.wilmer.children.service.IYwChildrenService;
import com.wilmer.common.utils.poi.ExcelUtil;
import com.wilmer.common.core.page.TableDataInfo;

/**
 * 幼儿Controller
 * 
 * @author hans
 * @date 2024-05-19
 */
@RestController
@RequestMapping("/children/children")
public class YwChildrenController extends BaseController
{
    @Autowired
    private IYwChildrenService ywChildrenService;

    /**
     * 查询幼儿列表
     */
    @PreAuthorize("@ss.hasPermi('children:children:list')")
    @GetMapping("/list")
    public TableDataInfo list(YwChildren ywChildren)
    {
        startPage();
        List<YwChildren> list = ywChildrenService.selectYwChildrenList(ywChildren);
        return getDataTable(list);
    }

    /**
     * 导出幼儿列表
     */
    @PreAuthorize("@ss.hasPermi('children:children:export')")
    @Log(title = "幼儿", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YwChildren ywChildren)
    {
        List<YwChildren> list = ywChildrenService.selectYwChildrenList(ywChildren);
        ExcelUtil<YwChildren> util = new ExcelUtil<YwChildren>(YwChildren.class);
        util.exportExcel(response, list, "幼儿数据");
    }

    /**
     * 获取幼儿详细信息
     */
    @PreAuthorize("@ss.hasPermi('children:children:query')")
    @GetMapping(value = "/{children}")
    public AjaxResult getInfo(@PathVariable("children") Long children)
    {
        return success(ywChildrenService.selectYwChildrenByChildren(children));
    }

    /**
     * 新增幼儿
     */
    @PreAuthorize("@ss.hasPermi('children:children:add')")
    @Log(title = "幼儿", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YwChildren ywChildren)
    {
        return toAjax(ywChildrenService.insertYwChildren(ywChildren));
    }

    /**
     * 修改幼儿
     */
    @PreAuthorize("@ss.hasPermi('children:children:edit')")
    @Log(title = "幼儿", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YwChildren ywChildren)
    {
        return toAjax(ywChildrenService.updateYwChildren(ywChildren));
    }

    /**
     * 删除幼儿
     */
    @PreAuthorize("@ss.hasPermi('children:children:remove')")
    @Log(title = "幼儿", businessType = BusinessType.DELETE)
	@DeleteMapping("/{childrens}")
    public AjaxResult remove(@PathVariable Long[] childrens)
    {
        return toAjax(ywChildrenService.deleteYwChildrenByChildrens(childrens));
    }
}
